package com.ruoyi.lqm.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.lqm.domain.LqmCategorys;
import com.ruoyi.lqm.domain.LqmMaterial;
import com.ruoyi.lqm.service.AlimamaService;
import com.ruoyi.lqm.service.ILqmCategorysService;
import com.ruoyi.lqm.service.ILqmMaterialService;
import com.taobao.api.ApiException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.ArrayList;
import java.util.List;

/**
 * 首页 业务处理
 * Created by DELL on 2019/8/29.
 */
@Controller
public class LqmIndexController extends BaseController {

    @Autowired
    private AlimamaService alimamaService;
    @Autowired
    private ILqmCategorysService lqmCategorysService;
    @Autowired
    private ILqmMaterialService lqmMaterialService;
    /**
     * 首页
     */
    @GetMapping("/lqm")
    public String index(ModelMap mmap) {
        LqmCategorys lqmCategorys = new LqmCategorys();
        List<LqmCategorys> list = lqmCategorysService.selectLqmCategorysList(lqmCategorys);
        //主类目
        List<LqmCategorys> plist = new ArrayList<>();
        for(int i=0;i<list.size();i++){
            if(list.get(i).getParentId().equals("0")){
                plist.add(list.get(i));
            }
        }
        mmap.put("plist", plist);
        mmap.put("list", list);
        mmap.put("navTab","lqm");
        mmap.put("rulesId",8);
        mmap.put("sortId",0);
        return "index2";
    }

    /**
     * 好券直播
     */
    @GetMapping("/lqm/zhibo/{Id}")
    public String zhibo(@PathVariable("Id") String Id, ModelMap mmap)
    {
        LqmMaterial lqmMaterial = new LqmMaterial();
        lqmMaterial.setRulesId("0");
        List<LqmMaterial> list = lqmMaterialService.selectLqmMaterialList(lqmMaterial);
        Long materialId =3756L;
        for(int i=0;i<list.size();i++){
            if(list.get(i).getSortId().equals(Id)){
                materialId = list.get(i).getMaterialId();
            }
        }
        Object data= null;
        try {
            data = alimamaService.TbkDgOptimusMaterialRequest(1L,materialId);
        } catch (ApiException e) {
            e.printStackTrace();
            AjaxResult.error();
        }
        mmap.put("navTab","zhibo");
        mmap.put("sortId",Id);
        mmap.put("LqmMaterial",list);
        mmap.put("data",new AjaxResult(AjaxResult.Type.SUCCESS,"", data));
        return "index_zhibo";
    }

    /**
     * 母婴生活
     */
    @GetMapping("/lqm/baby/{Id}")
    public String baby(@PathVariable("Id") String Id, ModelMap mmap)
    {
        LqmMaterial lqmMaterial = new LqmMaterial();
        lqmMaterial.setRulesId("2");
        List<LqmMaterial> list = lqmMaterialService.selectLqmMaterialList(lqmMaterial);
        Long materialId =4040L;
        for(int i=0;i<list.size();i++){
            if(list.get(i).getSortId().equals(Id)){
                materialId = list.get(i).getMaterialId();
            }
        }
        Object data= null;
        try {
            data = alimamaService.TbkDgOptimusMaterialRequest(1L,materialId);
        } catch (ApiException e) {
            e.printStackTrace();
            AjaxResult.error();
        }
        mmap.put("navTab","baby");
        mmap.put("sortId",Id);
        mmap.put("LqmMaterial",list);
        mmap.put("data",new AjaxResult(AjaxResult.Type.SUCCESS,"", data));
        return "index_baby";
    }

    /**
     * 大牌专场
     */
    @GetMapping("/lqm/brand/{Id}")
    public String brand(@PathVariable("Id") String Id, ModelMap mmap)
    {
        LqmMaterial lqmMaterial = new LqmMaterial();
        lqmMaterial.setRulesId("1");
        List<LqmMaterial> list = lqmMaterialService.selectLqmMaterialList(lqmMaterial);
        Long materialId =3786L;
        for(int i=0;i<list.size();i++){
            if(list.get(i).getSortId().equals(Id)){
                materialId = list.get(i).getMaterialId();
            }
        }
        Object data= null;
        try {
            data = alimamaService.TbkDgOptimusMaterialRequest(1L,materialId);
        } catch (ApiException e) {
            e.printStackTrace();
            AjaxResult.error();
        }
        mmap.put("navTab","brand");
        mmap.put("sortId",Id);
        mmap.put("LqmMaterial",list);
        mmap.put("data",new AjaxResult(AjaxResult.Type.SUCCESS,"", data));
        return "index_brand";
    }

    /**
     * 潮流街区
     */
    @GetMapping("/lqm/fashion/{Id}")
    public String fashion(@PathVariable("Id") String Id, ModelMap mmap)
    {
        LqmMaterial lqmMaterial = new LqmMaterial();
        lqmMaterial.setRulesId("4");
        List<LqmMaterial> list = lqmMaterialService.selectLqmMaterialList(lqmMaterial);
        Long materialId =4093L;
        for(int i=0;i<list.size();i++){
            if(list.get(i).getSortId().equals(Id)){
                materialId = list.get(i).getMaterialId();
            }
        }
        Object data= null;
        try {
            data = alimamaService.TbkDgOptimusMaterialRequest(1L,materialId);
        } catch (ApiException e) {
            e.printStackTrace();
            AjaxResult.error();
        }
        mmap.put("navTab","fashion");
        mmap.put("sortId",Id);
        mmap.put("LqmMaterial",list);
        mmap.put("data",new AjaxResult(AjaxResult.Type.SUCCESS,"", data));
        return "index_fashion";
    }

    /**
     * 好货推荐
     */
    @GetMapping("/lqm/recommend/{Id}")
    public String recommend(@PathVariable("Id") String Id, ModelMap mmap)
    {
        LqmMaterial lqmMaterial = new LqmMaterial();
        lqmMaterial.setRulesId("5");
        List<LqmMaterial> list = lqmMaterialService.selectLqmMaterialList(lqmMaterial);
        Long materialId =4092L;
        for(int i=0;i<list.size();i++){
            if(list.get(i).getSortId().equals(Id)){
                materialId = list.get(i).getMaterialId();
            }
        }
        Object data= null;
        try {
            data = alimamaService.TbkDgOptimusMaterialRequest(1L,materialId);
        } catch (ApiException e) {
            e.printStackTrace();
            AjaxResult.error();
        }
        mmap.put("navTab","recommend");
        mmap.put("sortId",Id);
        mmap.put("LqmMaterial",list);
        mmap.put("data",new AjaxResult(AjaxResult.Type.SUCCESS,"", data));
        return "index_recommend";
    }

    /**
     * 特惠专场
     */
    @GetMapping("/lqm/sales/{Id}")
    public String sales(@PathVariable("Id") String Id, ModelMap mmap)
    {
        LqmMaterial lqmMaterial = new LqmMaterial();
        lqmMaterial.setRulesId("6");
        List<LqmMaterial> list = lqmMaterialService.selectLqmMaterialList(lqmMaterial);
        Long materialId =4094L;
        for(int i=0;i<list.size();i++){
            if(list.get(i).getSortId().equals(Id)){
                materialId = list.get(i).getMaterialId();
            }
        }
        Object data= null;
        try {
            data = alimamaService.TbkDgOptimusMaterialRequest(1L,materialId);
        } catch (ApiException e) {
            e.printStackTrace();
            AjaxResult.error();
        }
        mmap.put("navTab","sales");
        mmap.put("sortId",Id);
        mmap.put("LqmMaterial",list);
        mmap.put("data",new AjaxResult(AjaxResult.Type.SUCCESS,"", data));
        return "index_sales";
    }

}
